package com.quanyan.orderpay.web.admin;

import com.quanyan.api.APIResponse;
import com.quanyan.api.enums.ApiResponseEnum;
import com.quanyan.common.utils.ValidationResult;
import com.quanyan.common.utils.ValidationUtils;
import com.quanyan.orderpay.service.PayWaySettingService;
import com.quanyan.orderpay.vo.request.ReqChangeSettingVo;
import com.quanyan.orderpay.vo.request.RespPayWaySettingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by Zheng.Ke
 * Date 2016/8/15.
 */
@RestController
@RequestMapping("/admin/api/order/payWaySetting")
public class AdminPayWaySettingController {
    @Autowired
    private PayWaySettingService payWaySettingService;


    @RequestMapping(value = "/payWayList", method = RequestMethod.POST)
    public APIResponse<List<RespPayWaySettingVo>> payWayList() {
        return payWaySettingService.payWayList();
    }

    @RequestMapping(value = "/changeSetting", method = RequestMethod.POST)
    public APIResponse changeSetting(@RequestBody ReqChangeSettingVo vo) {
        ValidationResult result = ValidationUtils.validateEntity(vo);
        if (result.hasErrors()) {
            return APIResponse.returnFail(ApiResponseEnum.PARAMETER_INVALID, result.getErrorDesc());
        }
        int payId = vo.getPayId();
        byte enabled = vo.getEnabled();
        String platform = vo.getPlatform();
        return payWaySettingService.changeSetting(payId, platform, enabled);
    }

}
